<?php

class PengaduanController extends Controller
{
	/**
	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
	 * using two-column layout. See 'protected/views/layouts/column2.php'.
	 */
	public $layout='//layouts/column2';

	/*
	public function filters() {
        return array('rights',);
    }
    */
    
	public function actionView($id)
	{
		
		$this->render('view',array(
			'model'=>$this->loadModel($id),
		));
    }
	
	
	public function actionDetail($id)
	{
		
		$this->render('detail',array(
			'model'=>$this->loadModel($id),
		));
    }


    public function actionIndex()
	{
		$model = new Pengaduan;
		$info = Page::model()->find('page_kategori_id=4');


		if(isset($_POST['Pengaduan']))
		{
			$model->attributes=$_POST['Pengaduan'];
			if($model->save())
				$this->redirect(array('index','success'=>1));
		}

		$this->render('index',array(
			'model'=>$model,
			'info'=>$info,
		));
    }


	public function loadModel($id)
	{
		$model=Pengaduan::model()->findByPk($id);
		if($model===null)
			throw new CHttpException(404,'The requested page does not exist.');
		return $model;
	}
		


		public function actionList()
        {
				$criteria=new CDbCriteria;
				$criteria->order = 'id desc';
                $dataProvider=new CActiveDataProvider('Pengaduan', array(
                        'criteria'=>$criteria,
                        'pagination'=>array(
                                'pageSize'=>10,
                                'pageVar'=>'page',
                        ),
                        'sort'=>array(
                                //'defaultOrder'=>'created_time',
                        ),
                ));
                $this->render('list',array(
                        'dataProvider'=>$dataProvider,
                ));
        }




	/**
	 * Performs the AJAX validation.
	 * @param CModel the model to be validated
	 */
	protected function performAjaxValidation($model)
	{
		if(isset($_POST['ajax']) && $_POST['ajax']==='posting-form')
		{
			echo CActiveForm::validate($model);
			Yii::app()->end();
		}
	}
        
}
